{% extends "base.html" %}

{% block title %}系统设置{% endblock %}

{% block content %}
<div class="container mt-4">
    <h1>系统设置</h1>
    <div class="card">
        <div class="card-body">
            <h5 class="card-title">系统配置</h5>
            <form method="post" action="{{ url_for('user_interface.settings') }}">
                <div class="form-group">
                    <label for="setting1">设置项 1</label>
                    <input type="text" class="form-control" id="setting1" name="setting1">
                </div>
                <div class="form-group">
                    <label for="setting2">设置项 2</label>
                    <input type="text" class="form-control" id="setting2" name="setting2">
                </div>
                <button type="submit" class="btn btn-primary mt-3">保存设置</button>
            </form>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
window.addEventListener('load', function() {
    new Vue({
        el: '.settings-container',
        data() {
            return {
                basicForm: {
                    systemName: '舆情监控系统',
                    refreshInterval: '300',
                    language: 'zh'
                },
                notificationForm: {
                    emailEnabled: true,
                    smsEnabled: false,
                    levels: ['high', 'medium']
                },
                dataForm: {
                    retentionPeriod: '90',
                    autoBackup: true,
                    backupFrequency: 'weekly'
                }
            }
        },
        methods: {
            async saveSettings() {
                try {
                    const settings = {
                        basic: this.basicForm,
                        notification: this.notificationForm,
                        data: this.dataForm
                    };
                    
                    const data = await window.store.fetchData('/api/settings', {
                        method: 'POST',
                        body: JSON.stringify(settings)
                    });
                    
                    if (data) {
                        window.ElementUI.Message.success('设置保存成功');
                    }
                } catch (error) {
                    window.ElementUI.Message.error('设置保存失败');
                }
            },
            resetSettings() {
                this.$confirm('确定要重置所有设置吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // 重置表单
                    this.$refs.basicForm.resetFields();
                    this.$refs.notificationForm.resetFields();
                    this.$refs.dataForm.resetFields();
                    window.ElementUI.Message.success('设置已重置');
                }).catch(() => {});
            }
        }
    });
});
</script>
{% endblock %} 